package com.sxt.springboot.config;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置.do   .action
 * @author LJH
 *
 */
@Configuration
public class UrlMatchConfig implements WebMvcConfigurer{

	
	@Override
	public void configurePathMatch(PathMatchConfigurer configurer) {
		// setUseSuffixPatternMatch 启用后缀模式匹配
		configurer.setUseSuffixPatternMatch(true);
		// setUseTrailingSlashMatch 自动后缀路径模式匹配
		configurer.setUseTrailingSlashMatch(true);
	}
	
	/**
	 * 处理加入后缀之后静态资源无法访问的问题
	 * 更改dispatcherServlet的url-patten
	 */
	@Bean
	public ServletRegistrationBean<DispatcherServlet> getDispatcherServlet(DispatcherServlet dispatcherServlet){
		ServletRegistrationBean<DispatcherServlet> servletServletRegistrationBean = new ServletRegistrationBean<DispatcherServlet>(
				dispatcherServlet);
		servletServletRegistrationBean.addUrlMappings("*.html");
		servletServletRegistrationBean.addUrlMappings("*.css");
		servletServletRegistrationBean.addUrlMappings("*.js");
		servletServletRegistrationBean.addUrlMappings("*.png");
		servletServletRegistrationBean.addUrlMappings("*.gif");
		servletServletRegistrationBean.addUrlMappings("*.ico");
		servletServletRegistrationBean.addUrlMappings("*.jpeg");
		servletServletRegistrationBean.addUrlMappings("*.jpg");
	    servletServletRegistrationBean.addUrlMappings("*.action");//后缀
	    return servletServletRegistrationBean;
	    
	}
}
